package com.ibiaoke.boss.controller;

import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.marketing.entity.Coupon;
import com.ibiaoke.marketing.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * Created by huhaichao on 2017/6/16.
 */
@Controller
public class BossCouponController {

    @Autowired
    private CouponService couponService;

    /**
     *添加优惠券
     */
    @ResponseBody
    @RequestMapping("/saveCoupon")
    public Res saveCoupon(Coupon coupon){
        couponService.saveCoupon(coupon);
        return Res.create();
    }


    /**
     *优惠券修改
     */
    @ResponseBody
    @RequestMapping("/updateCoupon")
    public Res updateCoupon(Coupon coupon){
        couponService.updateCoupon(coupon);
        return Res.create();
    }


    /**
     *优惠券删除
     */
    @ResponseBody
    @RequestMapping("/deleteCoupon")
    public Res deleteCoupon(Integer couponId){
        couponService.deleteCoupon(couponId);
        return Res.create();
    }

    /**
     *优惠券查询
     */
    @ResponseBody
    @RequestMapping("/listCoupon")
    public Res listCoupon(String couponName,Integer useType,Date beginTime,Date endTime,Page page){
        List<Coupon> coupons=couponService.listCoupon(couponName, useType,beginTime,endTime,page);
        return Res.create().addResponse("coupons",coupons).addResponse("page",page);
    }

    /**
     *优惠券获取
     */
    @ResponseBody
    @RequestMapping("/getCoupon")
    public Res getCoupon(Integer couponId){
        Coupon coupon=couponService.getCoupon(couponId);
        return Res.create().addResponse("coupon",coupon);
    }
}
